#include "drv_wifi.h"
void usart_sendstr(USART_TypeDef * USARTx,char *str,uint8_t size)
{
	uint8_t i=0;
	USART_ClearFlag(USARTx,USART_FLAG_TC);
	for(;i<size;i++)
	{
		USART_SendData(USARTx,*str);
		while(USART_GetFlagStatus(USARTx,USART_FLAG_TC));
		USART_ClearFlag(USARTx,USART_FLAG_TC);
		str++;
	}
}
void drv_wifi_init(void)
{ 
	usart_sendstr(USART3,"TC\r\n",4);
	
	if(strcmp(recv_wifi,"OK\r\n")!=0)
	{
		printf("can not TC\r\n");
	}
	
	usart_sendstr(USART3,"AT+CWMODE=2\r\n",13);	
	
	if(strcmp(recv_wifi,"OK\r\n")!=0)
	{
		printf("MODE2 is err\r\n");
	}
		
	usart_sendstr(USART3,"AT+CWSAP_DEF=\"Zydsg13\",\"12345678\",5,3\r\n",39);	
	
	if(strcmp(recv_wifi,"OK\r\n")!=0)
	{
		printf("MODE2 is err\r\n");
	}

	usart_sendstr(USART3,"AT+CIPMUX=1\r\n",13);

	if(strcmp(recv_wifi,"OK\r\n")!=0)
	{
		printf("MUX is err\r\n");
	}

	usart_sendstr(USART3,"AT+CIPSERVER=1,2020\r\n",21);

	if(strcmp(recv_wifi,"OK\r\n")!=0)
	{
		printf("SERVER is OK\r\n");
	}
	
	if(strcmp(recv_wifi,"0,CONNECT\r\n")==0)
	{
		printf("0 had conect\r\n");
	}
	
	if(strcmp(recv_wifi,"+IPD,0,6:open\r\n")==0)
	{
		strcpy(recv,"open\r\n");
		ready_char=1;
	}
	else if(strcmp(recv_wifi,"+IPD,0,6:clos\r\n")==0)
	{
		strcpy(recv,"clos\r\n");
		ready_char=1;

	}
		else if(strcmp(recv_wifi,"+IPD,0,5:run\r\n")==0)
	{
		strcpy(recv,"run\r\n");
		ready_char=1;
	}
		else if(strcmp(recv_wifi,"+IPD,0,3:!\r\n")==0)
	{
		strcpy(recv,"!\r\n");
		ready_char=1;
	}
		else if(strcmp(recv_wifi,"+IPD,0,7:stand\r\n")==0)
	{
		strcpy(recv,"stand\r\n");
		ready_char=1;
	}
		else if(strcmp(recv_wifi,"+IPD,0,5:lie\r\n")==0)
	{
		strcpy(recv,"lie\r\n");
		ready_char=1;
	}
		else if(strcmp(recv_wifi,"+IPD,0,6:temp\r\n")==0)
	{
		strcpy(recv,"temp\r\n");
		ready_char=1;
	}
		else if(strcmp(recv_wifi,"+IPD,0,3:~\r\n")==0)
	{
		strcpy(recv,"~\r\n");
		ready_char=1;
	}
}
